/***********************************************************************
 * Module:  Subject.java
 * Author:  DAC
 * Purpose: Defines the Class Subject
 ***********************************************************************/
package com.group1.model;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

/** @pdOid aee776ff-f4be-4ab7-a6a3-1d0e9cdd67d0 */
public class Subject {
   /** @pdOid 51b94036-903f-48ce-b6f6-4a746686b2c8 */
   protected void finalize() {
      // TODO: implement
   }
   
   /** @pdOid 30cad0df-01c8-4808-be16-6fb157849957 */
   public java.lang.String subjectId;
   /** @pdOid 506055e6-3464-42f6-b161-4e29fac847ff */
   public java.lang.String subjectName;
   /** @pdOid b8d80637-4923-4c7e-b8e7-f4dbbe29e525 */
   public java.lang.String subjectShortname;
   
   /** @pdRoleInfo migr=no name=Topic assc=topicsInsideOfSubject coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public java.util.Collection<Topic> topic;

   
   /** @param session
    * @pdOid 175bc550-ce7e-4c07-ac3f-abe564293373 */
   public static List<Subject> getAllSubject(Session session) {
	   Query query = session.createQuery("from Subject");                
	   List <Subject> listOfSubject = query.list();
	   return listOfSubject;
   }
   
   /** @param subjectID 
    * @param session
    * @pdOid 5c18fd78-afca-4709-a890-5d8243dd4e1c */
   public static Subject getSubjectByID(String subjectID, Session session) {
      // TODO: implement
	   return (Subject) session.load(Subject.class, subjectID);
   }
   
   
   /** @pdOid 6ba686ed-fc70-4445-b613-ee7a9dc184b4 */
   public java.lang.String getSubjectId() {
      return subjectId;
   }
   
   /** @param newSubjectId
    * @pdOid ec4a96a9-312e-49a0-9ef8-6be4d4abdf02 */
   public void setSubjectId(java.lang.String newSubjectId) {
      subjectId = newSubjectId;
   }
   
   /** @pdOid 2f9dfaec-333f-4963-a91e-f53de1d97beb */
   public java.lang.String getSubjectName() {
      return subjectName;
   }
   
   /** @param newSubjectName
    * @pdOid 0cd9ecf9-5be6-4ff6-9310-a623f78c1cbb */
   public void setSubjectName(java.lang.String newSubjectName) {
      subjectName = newSubjectName;
   }
   
   /** @pdOid 18e0a6ad-6efd-4a66-ae95-28ca1880b820 */
   public java.lang.String getSubjectShortname() {
      return subjectShortname;
   }
   
   /** @param newSubjectShortname
    * @pdOid a64d6ba6-e671-454d-b9aa-76fed2b8e343 */
   public void setSubjectShortname(java.lang.String newSubjectShortname) {
      subjectShortname = newSubjectShortname;
   }
   
   /** @pdOid dc334ecc-c09b-4ba5-98af-db629bd67d57 */
   public Subject() {
      // TODO: implement
   }
   
   /** @param subjectID 
    * @param subjectName 
    * @param shortName
    * @pdOid e05360c0-6722-4ca7-917a-17354c627acc */
   public Subject(String subjectID, String subjectName, String shortName) {
      // TODO: implement
	   this.subjectId = subjectID;
	   this.subjectName = subjectName;
	   this.subjectShortname = shortName;
   }
   
   
   /** @pdGenerated default getter */
   public java.util.Collection<Topic> getTopic() {
      if (topic == null)
         topic = new java.util.HashSet<Topic>();
      return topic;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorTopic() {
      if (topic == null)
         topic = new java.util.HashSet<Topic>();
      return topic.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newTopic */
   public void setTopic(java.util.Collection<Topic> newTopic) {
      removeAllTopic();
      for (java.util.Iterator iter = newTopic.iterator(); iter.hasNext();)
         addTopic((Topic)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newTopic */
   public void addTopic(Topic newTopic) {
      if (newTopic == null)
         return;
      if (this.topic == null)
         this.topic = new java.util.HashSet<Topic>();
      if (!this.topic.contains(newTopic))
      {
         this.topic.add(newTopic);
         newTopic.setSubject(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldTopic */
   public void removeTopic(Topic oldTopic) {
      if (oldTopic == null)
         return;
      if (this.topic != null)
         if (this.topic.contains(oldTopic))
         {
            this.topic.remove(oldTopic);
            oldTopic.setSubject((Subject)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllTopic() {
      if (topic != null)
      {
         Topic oldTopic;
         for (java.util.Iterator iter = getIteratorTopic(); iter.hasNext();)
         {
            oldTopic = (Topic)iter.next();
            iter.remove();
            oldTopic.setSubject((Subject)null);
         }
      }
   }

}